package com.shuyun.demo1;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.observers.DisposableObserver;
import org.junit.jupiter.api.Test;

/**
 * @description:
 * @author: shuai.chen@shuyun.com
 * @date: 2023/1/13 3:43 PM
 */
public class SubscribeDemo {

    @Test
    public void subscribe() {
        Observable<String> observable = Observable.just("a", "b", "c");
        // 参数： onNext  onError
        Disposable disposable = observable.subscribe(s -> System.out.println(s), e -> e.printStackTrace());

        disposable.dispose();
    }

    @Test
    public void subscribeWith() {
        Observable<String> observable = Observable.just("a", "b", "c");
        observable.subscribeWith(new DisposableObserver<String>() {
            @Override
            public void onNext(@NonNull String s) {
                System.out.println(s);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                System.out.println("onComplete");
            }

            @Override
            public void onComplete() {
                System.out.println("onComplete");
            }
        });
    }

}
